import {storeBindingsBehavior} from "mobx-miniprogram-bindings";
import {store} from "../store/store"


Component({
    options: {
        // 样式覆盖，设置为shared 
        styleIsolation: "shared"
    },
    // 组件中使用mobx
    behaviors: [storeBindingsBehavior],
    storeBindings: {
        store,
        fields: {
            // 选中项索引
            active: 'activeTabBarIndex'
        },
        actions: {
            // 更新tabbar选中项索引
            updateActive: "updateActiveTabBarIndex"
        }
    },
    /**
     * 组件的属性列表
     */
    properties: {

    },

    /**
     * 组件的初始数据
     */
    
    data: {
        list: [
            {
                "pagePath": "/pages/home/home/index",
                "text": "首页",
                "iconPath": "/static/tabbar/home.png",
                "selectedIconPath": "/static/tabbar/home-select.png"
            },
            {
                "pagePath": "/pages/monitor/home/index",
                "text": "用电监测",
                "iconPath": "/static/tabbar/monitor.png",
                "selectedIconPath": "/static/tabbar/monitor-select.png"
            },
            {
                "pagePath": "/pages/analysis/home/index",
                "text": "能效分析",
                "iconPath": "/static/tabbar/analysis.png",
                "selectedIconPath": "/static/tabbar/analysis-select.png"
            },
            {
                "pagePath": "/pages/my/home/index",
                "text": "我的",
                "iconPath": "/static/tabbar/my.png",
                "selectedIconPath": "/static/tabbar/my-select.png"
            }
        ]
    },
    

    /**
     * 组件的方法列表
     */
    methods: {
        onChange(event) {
            // 通过mobx更新tabbar选中项索引
            this.updateActive(event.detail)
            wx.switchTab({
              url: this.data.list[event.detail].pagePath,
            })
        }
    }
})
